package com.jt.controller;

import com.jt.pojo.ImageVO;
import com.jt.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/11/4
 */
@RestController
public class FileController {

    @Autowired
    private FileService fileService;


    @RequestMapping("/file")
    public String file(MultipartFile fileImage) throws IOException {

        String name = fileImage.getOriginalFilename();
        String dirPath = "D:/JT-SOFT/images";
        File dirfile = new File(dirPath);
        if (!dirfile.exists()){
            dirfile.mkdirs();
        }
        fileImage.transferTo(new File((dirPath+"/"+name)));
        return "文件上传成功";


    }

    @RequestMapping("/pic/upload")
    public ImageVO upload(MultipartFile uploadFile){

        return fileService.upload(uploadFile);
    }
}
